package cn.itsource.pethome.dictionary.controller;

import cn.itsource.pethome.basic.util.PageInfo;
import cn.itsource.pethome.basic.util.Result;
import cn.itsource.pethome.dictionary.domain.Systemdictionarydetail;
import cn.itsource.pethome.dictionary.domain.Systemdictionarytype;
import cn.itsource.pethome.dictionary.query.DictionarydetailQuery;
import cn.itsource.pethome.dictionary.service.IDctionaryService;
import cn.itsource.pethome.dictionary.service.IDictionarydetailService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/detail")
public class DictionarydetailController {
    @Autowired
    IDictionarydetailService dictionarydetailService;
    @Autowired
    IDctionaryService dctionaryService;

    //分页列表
    @PatchMapping
    public PageInfo<Systemdictionarydetail> findPageByQuery(@RequestBody DictionarydetailQuery dictionarydetailQuery){

        return dictionarydetailService.findPageByQuery(dictionarydetailQuery);
    }

    @PatchMapping("/findtypesId")
    //Swagger 注解  中文备注
    @ApiOperation(value = "查询所有上级经理")
    public List<Systemdictionarytype> findtypesId() {
        return dctionaryService.findtypesId();
    }

    //添加数据
    @PostMapping
    public Result save(@RequestBody Systemdictionarydetail systemdictionarydetail){
        try {
            dictionarydetailService.save(systemdictionarydetail);
            return new Result();

        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,e.getMessage());
        }
    }

    //删除请求路径（根据id）
    @DeleteMapping("/{id}")
    //删除
    //@PathVariable("id")   resetful风格注解，将参数作为url地址一部分传递过来
    public Result delete(@PathVariable("id") Long id) {
        try {

            dictionarydetailService.delete(id);
            return new Result();
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, e.getMessage());
        }
    }

}
